package org.hackystat.sdsa.analyzer.control.compressor;

/**
 * Utility class for activity compression.
 * 
 * @author hongbing
 *
 */
public class CompressorUtil {
  /**
   * Defines an inner class as a holder of begin and end index.
   * 
   * @author hongbing
   *
   */
  static class BeginEndPair {
    /** Begin index. */
    private int begin = -1;
    /** End index */
    private int end = -1;
    
    /**
     * Gets the begin index.
     * 
     * @return Begin index.
     */
    public int getBegin() {
      return this.begin;  
    }
    
    /**
     * Gets the end index.
     * 
     * @return End index.
     */
    public int getEnd() {
      return this.end;  
    }
    
    /**
     * Check whether the begin end is valid or not.
     * @return True if valid.
     */
    boolean isValid() {
      return this.begin >= 0;  
    }
    
    /**
     * Checks whether it is a multiple edit activity or not.
     * 
     * @return True if it is multiple.
     */
    boolean isMultiple() {
      return end >= 0;     
    }

    /**
     * Sets the beginning index.
     * @param begin Begin index.
     */
    public void setBegin(int begin) {
      this.begin = begin;
    }

    /**
     * Sets the end index.
     * 
     * @param end End index.
     */
    public void setEnd(int end) {
      this.end = end;
    }

    /**
     * Returns the number of activities.
     * 
     * @return Length.
     */
    public int length() {
      if (this.begin == -1) {
        return 0;
      }
      
      if (this.end == -1) {
        return 1;
      }
      
      return this.end - this.begin + 1;
    }
  }
}
